package com.android.demos.module.appbarstyle;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.aaron.android.framework.base.ui.BaseFragment;
import com.aaron.android.framework.base.widget.recycleview.RecyclerItemDecoration;
import com.aaron.android.framework.base.widget.recycleview.SimpleItemTouchHelperCallback;
import com.android.demos.R;
import com.android.demos.module.appbarstyle.adpater.AppBarStyleRecyclerAdapter;

import java.util.Arrays;

/**
 * Created on 16/5/3.
 *
 * @author aaron.huang
 * @version 1.0.0
 */
public abstract class AppBarStyleFragment extends BaseFragment {
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        RecyclerView recyclerView = (RecyclerView) inflater.inflate(R.layout.fragment_app_bar_style, null, false);
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.addItemDecoration(new RecyclerItemDecoration(getActivity(), LinearLayoutManager.VERTICAL, R.drawable.main_recycler_divider));
        AppBarStyleRecyclerAdapter appBarStyleRecyclerAdapter = new AppBarStyleRecyclerAdapter(getActivity());
        String[] datas = getResources().getStringArray(R.array.app_bar_style_item);
        appBarStyleRecyclerAdapter.setData(Arrays.asList(datas));
        recyclerView.setAdapter(appBarStyleRecyclerAdapter);
        ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new SimpleItemTouchHelperCallback(appBarStyleRecyclerAdapter));
        itemTouchHelper.attachToRecyclerView(recyclerView);
        return recyclerView;
    }
}
